package org.anyin.gitee.cloud.center.gateway.config;

import org.anyin.gitee.cloud.center.gateway.handler.HomeHandler;
import org.anyin.gitee.cloud.center.gateway.handler.ImageCodHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class HandlerFunctionConfig {

    @Autowired
    private HomeHandler homeHandler;

    @Autowired
    private ImageCodHandler imageCodHandler;

    @Bean
    public RouterFunction<ServerResponse> homeHandlerFunction() {
        return RouterFunctions.route(
                RequestPredicates.path("/home")
                        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), homeHandler);
    }

    @Bean
    public RouterFunction<ServerResponse> imageCodeHandlerFunction() {
        return RouterFunctions.route(
                RequestPredicates.path("/getImageCode")
                        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodHandler);
    }
}
